<template>
    <h1>EL-员工列表综合练习</h1>
    <el-form style="width:500px; margin:0 auto;" label-width="80px">
        <el-form-item label="姓名">
            <el-input v-model="u.name" placeholder="请输入姓名"></el-input>
        </el-form-item>
        <el-form-item label="薪资">
            <el-input v-model="u.salary" placeholder="请输入薪资"></el-input>
        </el-form-item>
        <el-form-item label="岗位">
            <el-input v-model="u.job" placeholder="请输入岗位"></el-input>
        </el-form-item>
        <el-button type="primary" @click="add" style="float: left;">提交</el-button>
    </el-form>
    <br>
    <br>
    <br>
    
    <el-table :data="u2" style="width: 600px; margin: 0 auto">
        <el-table-column type="index" label="编号" width="80px" align="center"></el-table-column>
        <el-table-column prop="name" label="姓名" align="center"></el-table-column>
        <el-table-column prop="salary" label="薪资" align="center"></el-table-column>
        <el-table-column prop="job" label="岗位" align="center"></el-table-column>
        <el-table-column label="操作">
            <template #default="scope">
                <el-button type="danger" @click="del(scope.$index, scope.row)">删除</el-button>
            </template>
        </el-table-column>
    </el-table>
</template>

<script setup>
import { ref } from 'vue'
import { useStore } from 'vuex'
import {ElMessage} from "element-plus";
const store = useStore()
const u = ref({
    name: '',
    salary: '',
    job: ''
})
const u2 = ref([])
const add = () => {
    u2.value.push(u.value);
    u.value = {
        name: '',
        salary: '',
        job: ''
    };
}
const del = (index,u) => {
    if (confirm("确定要将"+u.name+"删除吗？")){
        u2.value.splice(index, 1);
        ElMessage.success(u.name+  "删除成功")
    }else {
        ElMessage.error(u.name + "取消删除")
    }
}

</script>

<style scoped>

</style>